package pers.qianyu.month_202104.date_20210404;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 5723. 查找用户活跃分钟数
 * https://leetcode-cn.com/contest/weekly-contest-235/problems/finding-the-users-active-minutes/
 *
 * @author mizzle rain
 * @date 2021-04-04 11:12
 */
public class FindingUsersActiveMinutes {
    public int[] findingUsersActiveMinutes(int[][] logs, int k) {
        int[] answer = new int[k];
        int n = logs.length;
        if (n == 0) return answer;
        HashMap<Integer, Set<Integer>> idTimeMap = new HashMap<>();
        for (int[] log : logs) {
            int id = log[0];
            int time = log[1];
            idTimeMap.putIfAbsent(id, new HashSet<>());
            idTimeMap.get(id).add(time);
        }
        HashMap<Integer, Integer> countMap = new HashMap<>();
        for (Set<Integer> set : idTimeMap.values()) {
            int cnt = set.size();
            countMap.put(cnt, countMap.getOrDefault(cnt, 0) + 1);
        }
        for (Map.Entry<Integer, Integer> entry : countMap.entrySet()) {
            Integer key = entry.getKey();
            Integer value = entry.getValue();
            answer[key - 1] = value;
        }
        return answer;
    }
}
